package com.zzl.alligator.management.system.controller;

import com.zzl.alligator.common.enums.BusinessTypeEnum;
import com.zzl.alligator.common.util.ExcelUtils;
import com.zzl.alligator.framework.aspectj.annotation.Log;
import com.zzl.alligator.framework.base.controller.BaseController;
import com.zzl.alligator.framework.support.web.vo.JsonResult;
import com.zzl.alligator.management.system.domain.SysLoginRecord;
import com.zzl.alligator.management.system.service.ISysLoginRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统访问记录(SysLoginRecord)控制层
 *
 * @author zhouziliang
 * @since 2020-07-07
 */
@RestController
@RequestMapping("/system/loginrecord")
public class SysLoginRecordController extends BaseController {
    
    /**
     * 服务对象
     */
    @Autowired
    private ISysLoginRecordService sysLoginRecordService;

    /**
     * 分页查询所有数据
     *
     * @param sysLoginRecord 查询实体
     * @return 所有数据
     */
    @GetMapping
    public JsonResult findList(SysLoginRecord sysLoginRecord) {
        startPage();
        List<SysLoginRecord> sysLoginRecordList = sysLoginRecordService.findSysLoginRecordList(sysLoginRecord);
        return JsonResult.success(getDataTable(sysLoginRecordList));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param recordId 主键
     * @return 单条数据
     */
    @GetMapping("/{recordId}")
    @PreAuthorize("@ss.hasPermi('system:loginrecord:query')")
    public JsonResult findById(@PathVariable Long recordId) {
        return JsonResult.success(sysLoginRecordService.findSysLoginRecordById(recordId));
    }





    /**
     * 删除数据
     *
     * @param recordId 主键
     * @return 删除结果
     */
    @DeleteMapping("/{recordId}")
    @PreAuthorize("@ss.hasPermi('system:loginrecord:remove')")
    @Log(title = "删除系统访问记录", businessType = BusinessTypeEnum.DELETE)
    public JsonResult delete(@PathVariable Long recordId) {
        return toAjax(this.sysLoginRecordService.deleteById(recordId));
    }

    /**
     * 清空数据
     *
     * @return 删除结果
     */
    @DeleteMapping
    @PreAuthorize("@ss.hasPermi('system:loginrecord:remove')")
    @Log(title = "删除系统访问记录", businessType = BusinessTypeEnum.DELETE)
    public JsonResult delete() {
        return toAjax(this.sysLoginRecordService.clean());
    }
    
    /**
     * 导出数据
     * 
     * @param sysLoginRecord 条件
     * @return 导出文件路径
     */
    @GetMapping("/export")
    @PreAuthorize("@ss.hasPermi('monitor:loginrecord:export')")
    @Log(title = "导出系统访问记录", businessType = BusinessTypeEnum.EXPORT)
    public JsonResult export(SysLoginRecord sysLoginRecord) {
        List<SysLoginRecord> list = sysLoginRecordService.findSysLoginRecordList(sysLoginRecord);
        ExcelUtils<SysLoginRecord> util = new ExcelUtils<>(SysLoginRecord.class);
        return util.exportExcel(list, "系统访问记录数据");
    }
}